import React, { Component } from 'react';
import store from '../../store'
import actions from '../../store/actions';

class Index extends Component {
  AddCarItem(item) {
    const action = actions.addCar(item)
    store.dispatch(action)
  }
  render() {
    const { location } = this.props
    const { url, desc, title } = location.state
    return (
      <div>
        <img src={ url } alt="" />
        <h3>{title}</h3>
        <p>{desc}</p>

        <button onClick={ () => this.AddCarItem(location.state) }>加入购物车</button>
      </div>
    );
  }
}
export default Index;
